package com.liangzhong.modules.Main.Mediator
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.mediator.BaseMediator;
	import com.liangzhong.proxyconstant.winebar.WinebarConst;
	import com.lz.football.module.wineBar.IWineAwardPanel;
	
	import flash.display.DisplayObject;
	
	import lz.controls.managers.PopUpManager;
	
	import org.puremvc.as3.interfaces.INotification;

	/**
	 * 通用面板处理 
	 * @author lake
	 * 
	 */	
	public class CommonMediator extends BaseMediator
	{
		/**
		 * MediatorName
		 */		
		public static const MediatorName :String = "CommonMediator";
		/**
		 *泡吧奖励面板 
		 */		
		private var wineAwardPanel			 :IWineAwardPanel;
		
		public function CommonMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
		}
		/**
		 * 注册感兴趣的命令
		 * @return 
		 * 
		 */		
		override public function listNotificationInterests():Array
		{
			return [WinebarConst.LEAVE_RESULT,
				WinebarConst.BUY_RESULT];
		}
		/**
		 * 捕获通知
		 * @param notification
		 * 
		 */		
		override public function handleNotification(notification:INotification):void
		{
			var obj :Object = notification.getBody();
			switch(notification.getName())
			{
				case WinebarConst.LEAVE_RESULT://酒吧泡吧结算
				{
					if(obj.exp == 0)
					{
						return;
					}
					//奖励面板
					wineAwardPanel = Reflection.createInstance("com.lz.football.module.wineBar.view.AwardPanel");
					wineAwardPanel.initUI();
					wineAwardPanel.data = notification.getBody();
					PopUpManager.addPopUp(wineAwardPanel as DisplayObject,GlobalDef.GameWindowContainer,GlobalDef.GameStage.stageWidth,GlobalDef.GameStage.stageWidth,true);
					break;
				}
				case WinebarConst.BUY_RESULT://购买返回
				{
					if(obj.retcode == 0)
					{
						if(wineAwardPanel && wineAwardPanel["parent"])
						{
							wineAwardPanel["parent"].removeChild(wineAwardPanel);
							wineAwardPanel.destroyView();
							wineAwardPanel = null;
						}
					}
					else
					{
						wineAwardPanel.buyRes(obj);
					}
					break;
				}
			}
		}
	}
}